/*
 * @Author: dzj
 * @Date: 2021-11-15 22:38:16
 * @Description:
 */
import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/Home.vue";
import Admin from "../views/Admin.vue";
// import Welcome from '../views/Welcome.vue'
import Users from "../views/Users.vue";
// import Orders from '../views/Orders.vue'
import AchievementAudit from "../views/AchievementAudit.vue";
import PortalAudit from "../views/PortalAudit.vue";
import Achievement from "../views/Achievement.vue";
// import Company from '../views/Company.vue'
import SearchPreview from '../components/SearchPreview.vue'
import SuperSearchPreview from '../components/SuperSearchPreview'
import Detail from '../views/Detail.vue'
import Mydoor from '../views/mydoor.vue'
import Mydoor2 from '../views/mydoorfalse.vue'
import Dooregister from '../views/doorregister.vue'
import Door from '../views/door.vue'
import Appeal from '../views/Appeal.vue'
import Companydoor from '../views/companydoor.vue'
import MyCompanydoor from '../views/mycompanydoor.vue'
import DoorAppeal from "../views/DoorAppeal.vue"
import AdminLogin from "../views/AdminLogin.vue";

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/searchpreview",
    name: "SearchPreview",
    component: SearchPreview,
  },
  {
    path: '/supersearchpreview',
    name: 'SuperSearchPreview',
    component: SuperSearchPreview
  },
  {
    path: '/detail',
    name: 'Detail',
    component: Detail
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
  {
    path: '/example',
    name: 'Example',
    component: () => import( '../views/Example.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import( '../views/Login.vue')
  },
  {
    path: '/wellheaderA',
    name: 'WellHeaderA',
    component: () => import( '../views/WellHeaderA.vue'),
    children:[
      {
        path: '/personalcenterforsee',
        name: 'PersonalCenterForSee',
        component: () => import('../views/PersonalCenterForSee.vue')
      },
      {
        path: '/personalcenterformodify',
        name: 'PersonalCenterForModify',
        component: () => import('../views/PersonalCenterForModify.vue')
      },
      {
        path: '/findpwd',
        name: 'FindPwd',
        component: () => import( '../views/FindPwd.vue')
      },
      {
        path: '/setpwd',
        name: 'SetPwd',
        component: () => import( '../views/SetPwd.vue')
      },

    ]
  },
  {
    path: '/mydoortrue',
    name:"mydoor",
    component: Mydoor
  },
  {
    path: '/mydoorfalse',
    component: Mydoor2
  },
  {
    path: '/doorregister',
    component: Dooregister
  },
  {
    path: '/doorappeal',
    name:'Doorappeal',
    component: DoorAppeal
  },
  {
    path: '/door',
    name:'Door',
    component: Door
  },
  {
    path: '/companydoor',
    name:"Companydoor",
    component: Companydoor
  },
  {
    path: '/mycompanydoor',
    name:"mycompanydoor",
    component: MyCompanydoor
  },
  {
    path: '/admin',
    name: 'Admin',
    component: Admin,
    redirect: "/users",
    children: [
      // {
      //   path: "/welcome",
      //   component: Welcome,
      // },
      {
        path: "/users",
        component: Users,
      },
      {
        path: "/portalAudit",
        component: PortalAudit,
      },
      {
        path: "/achievement",
        component: Achievement,
      },
      {
        path: "/achievementAudit",
        component: AchievementAudit,
      },
      // {
      //   path: "/company",
      //   component: Company
      // },
      {
        path: "/appeal",
        component: Appeal,
      },
    ],
  },
  {
    path: "/adminlogin",
    component: AdminLogin,
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

var notAllowed = ["/admin", "/users", "/portalAudit", "/achievement", "/achievementAudit", "/appeal"]

export default router;
router.beforeEach((to, from, next) => {
  if (to.path === "/searchpreview/:search") {
    //     axios.post('code/',input,typeGroup,value).then((response) => {
    //   this.$router.push('/searchpreview/'+this.input+response)
    // })
    next();
  } else if (notAllowed.indexOf(to.path) != -1) {
    console.log(localStorage.getItem("admin"))
    if (localStorage.getItem("admin") === "true") {
      next();
    } else {
      next("/adminlogin");
    }
  } else if (to.path === "/adminlogin"){
    if (localStorage.getItem("admin") === "true") {
      next("/admin");
    }
    else {
      next();
    }
  }
  else {
    next();
  }
});
// router.afterEach((to)=>{ //这里不接收next
//   if (
//     to.path === "/searchpreview"
//   ) {
//     if(Object.keys(to.params.input).length!==0){
//       localStorage.setItem('input', to.params.input);
//         localStorage.setItem('typeGroup', to.params.typeGroup);
//         localStorage.setItem('value', to.params.value);
//     }
//         let input=localStorage.getItem('input');
//         let typeGroup=localStorage.getItem('typeGroup');
//         let value=localStorage.getItem('value');
//         console.log(input);
//         console.log(typeGroup);
//         console.log(value);
//         console.log(111111111111111111111)
//         console.log(this.row_files)

//   }
// });
